package oop.java0322;

import java.util.Scanner;

/**
 * 定义一个字符串数组，输入一个字符串,从数组中删除,删除后,后面的往前移动,注意置空的处理...
 * 比如字符串为{"aa","bb","cc","ff"},如果bb被删除后,则为{"aa","cc","ff",null}
 */
public class ArrayDeleteTest {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] arr = new String[]{"aa", "bb", "cc", "ff"};
        int index = 0;
        boolean isFind = false;
        System.out.println("请输入一个字符串：");
        String str = in.next();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].equals(str)) {
                index = i;
                isFind=true;
            }
        }
        if(isFind){
            for (int i = index; i < arr.length - 1; i++) {
                arr[i] = arr[i + 1];
            }
            arr[arr.length - 1] = null;
            for (int i = 0; i < arr.length; i++) {
                System.out.print(arr[i] + "\t");
            }
            return;
        }
        System.out.println(str+"不在数组中");



    }
}
